#ifndef VSVERTEXFORMAT_H
#define VSVERTEXFORMAT_H
#include "VSObject.h"
#include "VSBind.h"
namespace VSEngine2
{
	class VSStream;
	class VSGRAPHIC_API VSVertexFormat : public VSBind
	{
		//PRIORITY
		
		//RTTI
		DECLARE_RTTI;
	public:

		VSVertexFormat();
		virtual ~VSVertexFormat();
		
		enum
		{
			VF_POSITION,
			VF_TEXCOORD,
			VF_NORMAL,
			VF_TANGENT,
			VF_BINORMAL,
			VF_PSIZE,
			VF_COLOR,
			VF_FOG,
			VF_DEPTH,
			VF_BLENDWEIGHT,
			VF_BLENDINDICES,
			VF_MAX
		};
		struct VERTEXFORMAT_TYPE
		{
		public:
			VERTEXFORMAT_TYPE()
			{
				OffSet = 0;
				DateType = 0;
				Semantics = 0;
				SemanticsIndex = 0;
			}
			~VERTEXFORMAT_TYPE()
			{

			}
			UINT OffSet;
			UINT DateType;
			UINT Semantics;
			UINT SemanticsIndex;
		};
	public:
		static bool RegisterMainFactory();
		/*static bool LoadAllDefault(VSRenderer *pRender);*/
		//static bool ReleaseAllDefault();

	private:
		static bool InitialClassFactory();	
		static VSObject * FactoryFunc();
		static bool ms_bRegisterMainFactory;
// 		static bool InitialDefaultState();
// 		static bool TerminalDefaultState();
	public:
		
		virtual unsigned int DiskUse()const;

		virtual bool Save(VSStream & rStream,unsigned int &iSaveUse)const;
		virtual bool Load(VSStream & rStream,unsigned int &iSaveUse);
		virtual bool RegisterSelf(VSStream & rStream)const;
	protected:
		/*static VSPointer<VSVertexFormat> DefaultVF[VF_MAX];*/
	public:
		friend class VSRenderer;
		friend class VSDX9Renderer;
// 		static const VSVertexFormat *GetDefalut(unsigned int i)
// 		{
// 			if(i >= VF_MAX)
// 				return  NULL;
// 			return DefaultVF[i];
// 		}
		friend class VSVShaderKey;
		friend class VSPShaderKey;
		friend class VSResourceManager;
		friend class VSShaderKey;
	public:
		virtual bool Clone(const VSObject *pObject,unsigned int uiType);

	protected:
		virtual bool OnLoadResource(VSResourceIdentifier *&pID);		
		virtual bool OnReleaseResource(VSResourceIdentifier *pID);
		unsigned int m_uiVertexFormatCode;
		// VSVertexBuffer * m_pCreateBy;
	public:
		
		VSArray<VSVertexFormat::VERTEXFORMAT_TYPE> m_FormatArray;
// 		inline void SetCreateBy(VSVertexBuffer * pCreateBy)
// 		{
// 			m_pCreateBy = pCreateBy;
// 		}
	};
	typedef VSPointer<VSVertexFormat> VSVertexFormatPtr;

}
#endif